package org.itcast.adi.webTemplate.controller;

import org.itcast.adi.planinfo.entity.ResultBean;
import org.itcast.adi.webTemplate.service.RestTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//  相关csdn博客： https://blog.csdn.net/scm_2008/article/details/127682333?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171783579416800215019863%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=171783579416800215019863&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-127682333-null-null.142^v100^pc_search_result_base1&utm_term=restTemplate%E7%9A%84exchange%E6%96%B9%E6%B3%95&spm=1018.2226.3001.4187
@RestController
@RequestMapping("/resttemplate")
public class RestTemplateController {
    @Autowired
    private RestTemplateService templateService;

    /**
     * url	调用的url地址
     * method	枚举值，HTTP方法：GET、POST、PUT、DELETE等
     * requestEntity	发起请求时携带的对象：请求头header 和/或 请求体body
     * responseType	请求响应对象的类型
     * uriVariables	就是针对url中的@PathVariable参数，可变长度参数列表
     */
    @GetMapping("/get1")
    public ResultBean get() {
        return templateService.get();
    }

    //    基本类型传参，和实体传参
    @PostMapping("/post1")
    public ResultBean post1() {
        return templateService.post();
    }

    //    @requestBody传参(也就是调用对方服务器的请求参数使用@requestBody注解的参数）
    @PostMapping("/post2")
    public ResultBean post2() {
        return templateService.post2();
    }

    //    exchange方法，可以调get,post请求  http://localhost:8080/planinfo/findAll
    @PostMapping("/exchange")
    public ResultBean exchange() {
        return templateService.exchange();
    }

    //    http://localhost:8080/planinfo/findById?planId="+"1"
    @GetMapping("/exchange1")
    public ResultBean exchange1() {
        return templateService.exchange1();
    }

    // http://localhost:8080/planinfo/findById/111?planDesc=test
    @GetMapping("/exchange2")
    public ResultBean exchange2() {
        return templateService.exchange2();
    }
//http://localhost:8080/planinfo/findAllOne/1   body {planDesc = test}
    @PostMapping("/exchange3")
    public ResultBean exchange3() {
        return templateService.exchange3();
    }


}
